package com.link.base.tencent.corpwx.appchat.controller;

import com.link.base.tencent.corpwx.appchat.model.AppChat;
import com.link.base.tencent.corpwx.appchat.service.AppChatService;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.cllog.LCLogger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * 应用群聊 
 *
 * @author 欧阳振强
 * @date 2020-01-03 10:37:47.0
 */
@Controller
@RequestMapping("/link/corpwx/appChat")
public class AppChatController extends BasicController<AppChat> {

    @Resource
    private AppChatService appChatService;

    @Override
    public BasicService<AppChat> getBasicService() throws Exception {
        return appChatService;
    }

    /**
     * 同步群聊到企业微信
     *
     * @author 欧阳振强
     * @date 2020/01/05
     */
    @PostMapping(value = "/syncAppChatToWx", name = "同步群聊到企业微信")
    @ResponseBody
    public Map<String, Object> syncAppChatToWx(@JsonParam AppChat record, HttpSession session, HttpServletRequest request) {
        Map<String, Object> result = new HashMap<String, Object>(4);
        try {
            appChatService.syncAppChatToWx(record);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }

    /**
     * 删除群聊
     * 
     * @author 欧阳振强
     * @date 2020/01/05
     */
    @PostMapping(value = "/delAppChatById", name = "删除群聊")
    @ResponseBody
    public Map<String, Object> delAppChatById(@JsonParam AppChat record, HttpSession session, HttpServletRequest request) {
        Map<String, Object> result = new HashMap<String, Object>(4);
        try {
            appChatService.delAppChatById(record);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }

    /**
     * 发送群聊文本消息
     *
     * @author 欧阳振强
     * @date 2020/01/05
     */
    @PostMapping(value = "/sendAppChatTextMsg", name = "发送群聊文本消息")
    @ResponseBody
    public Map<String, Object> sendAppChatTextMsg(@JsonParam AppChat record, HttpSession session, HttpServletRequest request) {
        Map<String, Object> result = new HashMap<String, Object>(4);
        try {
            appChatService.sendAppChatTextMsg(record);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }
}